package com.example.bestudentsystem.demos.web.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.example.bestudentsystem.demos.web.pojo.RateRecord;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

@Mapper
public interface RateMapper extends BaseMapper<RateRecord> {
    @Select("SELECT rr.* " +
            "FROM raterecord rr " +
            "JOIN sc ON rr.sno = sc.sno AND rr.cno = sc.cno " +
            "WHERE sc.status = '已评教'")
    IPage<RateRecord> selectRateByPage(IPage<RateRecord> iPage);
    @Select("select * from raterecord where cno = #{cno}")
    IPage<RateRecord> selectRateByCno(IPage<RateRecord> iPage,String cno);
    //更新评教状态
    @Update("update sc set status = #{status} where sno = #{sno} AND cno = #{cno}")
    int updateStatus(String sno,String cno,String status);
    @Update("update sc set status = #{status} where sno = #{sno}")
    int updateAllStatus(String status,String sno);
    //更新审核状态
    @Update("update raterecord set ischeck = #{ischeck} where sno = #{sno} AND cno = #{cno}")
    void updateCheck(String sno, String cno, String ischeck);

    //查询评教内容（学年，学期，教学内容，教学趣味，沟通表达，个人建议）
    @Select("select * from raterecord where sno = #{sno} AND cno = #{cno}")
    RateRecord selectRate(String sno,String cno);
    //查询已审核的评教记录
    @Select("select * from raterecord where tno = #{tno} AND ischeck = '审核通过' AND cno = #{cno}")
    IPage<RateRecord> selectCheckRate(IPage<RateRecord> iPage,String tno,String cno);
    //
    @Update("update raterecord set session = #{session},semester=#{semester},teaching_content=#{teachingContent}," +
            "teaching_fun=#{teachingFun},communication=#{communication},personal_advice=#{personalAdvice} where sno = #{sno} AND cno = #{cno}")
    int updateRate(RateRecord rateRecord);

}
